Categorise data so to specify colours and labels for the map
library(leaflet)
# Specify the colour palette
pal <- colorFactor(palette = c("red", "salmon1", "white", "steelblue1", "blue"),
levels = c("less than -2", "-2 to 0", "0", "0 to 2", "more than 2"), ordered = FALSE)
# pal <- colorBin("RdYlBu", domain = spdf$z_score, bins = bins)
# There is a list of all the available background tiles in
# http://leaflet-extras.github.io/leaflet-providers/preview/index.html
# Create the initial background map, zooming in Europe
colourmap <- leaflet() %>%
addTiles() %>%
setView(lat = 48, lng = 20, zoom = 4) %>%
addProviderTiles(providers$NASAGIBS.ViirsEarthAtNight2012, group = "NASAGIBS.ViirsEarthAtNight2012") %>%
addProviderTiles(providers$Stamen.TonerLite, group = "Stamen.TonerLite")
# Create the interactive map showing the sequence clusters
interactive_map <- colourmap %>%
addPolygons(data = combined_data_simpl,
fillColor = ~pal(z_cat),
weight = 0.4,
opacity = 0.8,
color = "black",
dashArray = "3",
fillOpacity = 0.7,
popup = paste("Name: ", combined_data_simpl$name, "<br>",
"Net Migration: ", combined_data_simpl$net_migr, "<br>"),
group = "Net migration in Europe",
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE)) %>%
addLegend(pal = pal,
values = combined_data_simpl$z_cat,
na.label = "Missing data",
position = "bottomleft",
title = "Net migration in Europe (z-scores)") %>%
addLayersControl(baseGroups = c("NASAGIBS.ViirsEarthAtNight2012", "Stamen.TonerLite"),
overlayGroups = "Net migration in Europe",
options = layersControlOptions(collapsed = FALSE))
interactive_map